import 'package:flutter/material.dart';
import 'package:mall/constant/app_dimens.dart';
import 'package:mall/constant/app_strings.dart';
import 'package:mall/constant/text_style.dart';
import 'package:mall/modules/model/home_entity.dart';
import 'package:mall/ui/widgets/cached_image.dart';
import 'package:mall/router/navigator_util.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class TabHomeBrand extends StatelessWidget {
  final List<HomeModelBrandlist> brands;
  final String title;
  TabHomeBrand(this.title, this.brands);

  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(left: 15, right: 15),
      child: Column(
        children: [
          Container(
            width: double.infinity,
            height: 45,
            alignment: Alignment.centerLeft,
            child: Text(
              title,
              style: FMTextStyle.color_333333_size_13_bold,
            ),
          ),
          ListView.builder(
              padding: EdgeInsets.all(0),
              itemCount: brands.length,
              shrinkWrap: true,
              physics: NeverScrollableScrollPhysics(),
              itemBuilder: (BuildContext context, int index) {
                return _itemView(context, brands[index]);
              }),
        ],
      ),
    );
  }

  _goBrandDetail(BuildContext context, HomeModelBrandlist brand) {
    NavigatorUtil.goBrandDetail(context, brand.name, brand.id);
  }

  Widget _itemView(BuildContext context, HomeModelBrandlist brand) {
    return Card(
      clipBehavior: Clip.antiAlias,
      child: Container(
        child: InkWell(
          onTap: () => _goBrandDetail(context, brand),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Container(
                width: double.infinity,
                child: CachedImageView(double.infinity, ScreenUtil().setHeight(AppDimens.DIMENS_400), brand.picUrl),
              ),
              Container(
                  padding: EdgeInsets.only(top: 15, left: 15),
                  child: Text(brand.name ?? "",
                      maxLines: 1, overflow: TextOverflow.ellipsis, style: FMTextStyle.color_222222_size_13)),
              Container(
                  padding: EdgeInsets.only(top: 15, left: 15),
                  child: Text(brand.desc ?? "",
                      maxLines: 2, overflow: TextOverflow.ellipsis, style: FMTextStyle.color_999999_size_13)),
              Container(
                  padding: EdgeInsets.only(top: 15, left: 15, bottom: 15),
                  child: Text(AppStrings.DOLLAR + "${brand.floorPrice}", style: FMTextStyle.color_ff5722_size_13)),
            ],
          ),
        ),
      ),
    );
  }
}
